package BDD;

import android.content.ContentValues;
import android.database.Cursor;
import android.view.View;
import com.example.activities.MainGallery;

/**
 * Created by IntelliJ IDEA.
 * User: isen
 * Date: 23/01/12
 * Time: 15:06
 * To change this template use File | Settings | File Templates.
 */
public class Queries {


    public static void checkMode( boolean isInSaveMode, String pictureName, String place, String contact)
    {
        if(isInSaveMode==true)
        {
            Queries.savePicture(pictureName, place, contact);
        }
        else
        {
            Queries.updatePicture(pictureName, place, contact);
        }
    }
    private static void savePicture(String pictureName, String place, String contact)
    {
        System.out.println("SAVE: "+pictureName);
        System.out.println("SAVE: "+place);
        System.out.println("SAVE: "+contact);
        ContentValues cvPicture = new ContentValues();
        cvPicture.put("_id", pictureName);
        cvPicture.put(DataBaseHelper.PERSON_NAME, contact);
        cvPicture.put(DataBaseHelper.PLACE, place);

        MainGallery.sqLiteDatabase.insert(
                DataBaseHelper.MAIN_TABLE,
                null,
               cvPicture);
    }


    public static Cursor getPicture(String pictureName)
    {
        Cursor c = MainGallery.sqLiteDatabase.query(
                DataBaseHelper.MAIN_TABLE,
                null,
                "_id="+ "\""+pictureName+ "\"",
                null,
                null,
                null,
                null);
        return c;
    }


    private static void updatePicture(String pictureName, String place, String contact)
    {
        ContentValues cvPicture = new ContentValues();
        System.out.println("UPDATE: "+pictureName);
        System.out.println("UPDATE: "+place);
        System.out.println("UPDATE: "+contact);
        cvPicture.put(DataBaseHelper.PERSON_NAME, contact);
        cvPicture.put(DataBaseHelper.PLACE, place);
        String strFilter = "_id=" + "\""+pictureName+ "\"";

        MainGallery.sqLiteDatabase.update(DataBaseHelper.MAIN_TABLE, cvPicture, strFilter, null);
    }
    
    public static void deletePicture(String pictureName)
    {
        MainGallery.sqLiteDatabase.delete(DataBaseHelper.MAIN_TABLE,"_id="+ "\""+pictureName+ "\"",null);
    }
}
